<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: controller.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

/**
 * JoomGPSTracks Component Controller
 */
class JoomgpstracksController extends JController {
	function display() {
        // Make sure we have a default view
        if( !JRequest::getCmd( 'view' )) {
		    JRequest::setVar('view', 'joomgpstracks' );
        }

		//update the hit count for the track
		if(JRequest::getCmd('view') == 'tracks')
		{
			$model =& $this->getModel('tracks');
			$model->hit();
		}

		parent::display();
	}

    /**
     * calls the captcha image
     */
    function displayimg()
    {
            global $mainframe;
            // By default, just display an image
            $document = &JFactory::getDocument();
            $doc = &JDocument::getInstance('raw');
            // Swap the objects
            $document = $doc;
	    $mainframe->triggerEvent('onCaptcha_display', array());
    }

    function vote()  {

        $id =& JRequest::getInt('id');
        $rate =& JRequest::getInt('rate');
        $model = $this->getModel('tracks');
        $model->vote($id, $rate);

        $msg = JText::_('GPS_VOTED');
        $this->setRedirect( JRoute::_('index.php?option=com_joomgpstracks&view=tracks&layout=track&id='.$id, false ));
    }



}
?>